﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Text;
using System.Threading.Tasks;

namespace BusinessLayer
{
	public class Email
	{
		public static SmtpClient Cliente()
		{
			#region Senha
			SmtpClient client = new SmtpClient("bybikeshop.com.br", 587);
			//client.EnableSsl = true;
			client.UseDefaultCredentials = true;
			client.Credentials = new NetworkCredential("bybike@bybikeshop.com.br", "Byb1ke@p3d4l3");
			#endregion
			return client;
		}

		public static void SendMail(string from, List<string> to, string subject, string body, bool isHtml = false)
		{
			MailMessage msg = new MailMessage();
			msg.From = new MailAddress(from);

			to.ForEach(a => msg.To.Add(new MailAddress(a)));

			msg.Subject = subject;
			msg.Body = body;
			msg.IsBodyHtml = isHtml;

			try
			{
				Cliente().Send(msg);

				//The SMTP server requires a secure connection or the client was not authenticated. The server response was 5.7.1 Authentication required
			}
			catch (Exception)
			{

				throw;
			}
		}
	}
}
